package com.erp.pro.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.erp.pro.domain.SupplierLogDO;
import com.erp.pro.service.SupplierLogService;
import com.erp.common.utils.PageUtils;
import com.erp.common.utils.Query;
import com.erp.common.utils.R;

/**
 * 供应商日志
 * 
 * @author Eric
 * @email shiliang900713@163.com
 * @date 2019-06-29 17:06:25
 */
 
@Controller
@RequestMapping("/pro/supplierLog")
public class SupplierLogController {
	@Autowired
	private SupplierLogService supplierLogService;
	
	@GetMapping()
	@RequiresPermissions("pro:supplierLog:supplierLog")
	String SupplierLog(){
	    return "pro/supplierLog/supplierLog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("pro:supplierLog:supplierLog")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<SupplierLogDO> supplierLogList = supplierLogService.list(query);
		int total = supplierLogService.count(query);
		PageUtils pageUtils = new PageUtils(supplierLogList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("pro:supplierLog:add")
	String add(){
	    return "pro/supplierLog/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("pro:supplierLog:edit")
	String edit(@PathVariable("id") Long id,Model model){
		SupplierLogDO supplierLog = supplierLogService.get(id);
		model.addAttribute("supplierLog", supplierLog);
	    return "pro/supplierLog/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("pro:supplierLog:add")
	public R save( SupplierLogDO supplierLog){
		if(supplierLogService.save(supplierLog)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("pro:supplierLog:edit")
	public R update( SupplierLogDO supplierLog){
		supplierLogService.update(supplierLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("pro:supplierLog:remove")
	public R remove( Long id){
		if(supplierLogService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("pro:supplierLog:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		supplierLogService.batchRemove(ids);
		return R.ok();
	}
	
}
